/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tos.pip;

import org.jdesktop.application.FrameView;
import tos.TosView;

/**
 *
 * @author Milos
 */
public class Proizvodjac extends Thread {

    public static int ukId = 0;
    private int id;
    private Skladiste skladiste;
    private int minVreme, maxVreme;
    private int proizvod;
    private FrameView parent;

    public Proizvodjac(Skladiste skladiste, int minVreme, int maxVreme, FrameView parent) {
        this.skladiste = skladiste;
        this.minVreme = minVreme;
        this.maxVreme = maxVreme;
        id = ++ukId;
        this.parent = parent;
    }

    public void run() {
        System.out.println("Proizvodjac " + id + " krenuo.");
        ((TosView) parent).appendOutput("Proizvodjac " + id + " krenuo.\n");
        try {
            while (((TosView) parent).zaustaviPip == false) {
                sleep((long) (minVreme + Math.random() * (maxVreme - minVreme)));
                proizvod = (int) (Math.random() * 1000);
                System.out.println("Proizvodjac " + id + " stavlja " + proizvod);
                ((TosView) parent).appendOutput("Proizvdjac " + id + " stavlja " + proizvod + "\n");
                skladiste.stavi(proizvod);
            }
            ((TosView) parent).appendOutput("Proizvodjac " + id + " je stao.\n");
        } catch (InterruptedException ir) {
        }
    }
}
